<template>

  <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="98px">
      <el-form-item label="生产单号" prop="produceNo">
        <el-input v-model="queryParams.produceNo" placeholder="请输入生产单号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="订单编号" prop="projectNo">
        <el-input v-model="queryParams.projectNo" placeholder="请输入订单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="工序名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入工序名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="产品名称" prop="goodsName">
        <el-input v-model="queryParams.goodsName" placeholder="请输入产品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="产品型号" prop="goodModel">
        <el-input v-model="queryParams.goodModel" placeholder="请输入产品型号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="图纸号" prop="shuoming">
        <el-input v-model="queryParams.shuoming" placeholder="请输入图纸号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="生产产品名称" prop="gongxuName">
        <el-input v-model="queryParams.gongxuName" placeholder="请输入生产产品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="生产产品型号" prop="gongxuModel">
        <el-input v-model="queryParams.gongxuModel" placeholder="请输入生产产品型号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--<el-form-item label="是否自制" prop="isdo">
        <el-select v-model="queryParams.isdo" placeholder="是否自制" clearable style="width: 130px">
          <el-option v-for="dict in dict.type.isdo"
                     :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>-->
      <el-form-item label="车间" prop="deptName">
        <el-select v-model="queryParams.deptName" placeholder="请选择车间" style="width: 100%" @change="handshopChange" clearable>
          <el-option v-for="(item, index) in workshopOptions" :key="index" :label="item.label" :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="分配人" prop="updateBy">
        <el-input v-model="queryParams.updateBy" placeholder="请输分配人" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="任务分配状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="任务分配状态" clearable style="width: 130px">
          <el-option v-for="dict in dict.type.task_status" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <!--<el-button type="warning" plain icon="el-icon-download" size="mini"
                   @click="handleExportDetail" >导出
        </el-button>-->
      </el-form-item>
    </el-form>

    <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table"
      :max-height="tableMaxHeight">
      <el-table-column align="center" label="序号" type="index" width="50">
        <template slot-scope="scope">
          <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column sortable label="生产单号" align="center" prop="prodNo" show-overflow-tooltip />
      <el-table-column sortable label="需求日期" align="center" prop="prodDaleDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.prodDaleDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column sortable label="订单编号" align="center" prop="projectCode" show-overflow-tooltip />
      <!-- <el-table-column label="工程名称" align="center" prop="gongchengName" show-overflow-tooltip />-->
      <el-table-column sortable label="产品编码" align="center" prop="goodsCode" />
      <!--<el-table-column sortable align="center" label="报工状态" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.gxbg_status" :value="scope.row.status" />
        </template>
      </el-table-column>-->
      <el-table-column sortable align="center" label="产品名称" prop="goodsName" show-overflow-tooltip />
      <el-table-column sortable align="center" label="产品型号" prop="goodsModel" />
      <el-table-column sortable align="center" label="工序名称" prop="name" />
      <el-table-column sortable align="center" label="生产产品名称" prop="gongxuName" />
      <el-table-column sortable align="center" label="生产产品型号" prop="gongxuModel" />
      <el-table-column sortable align="center" label="工序单价" prop="money" />
      <el-table-column sortable align="center" label="工序总价" prop="allMoney" />
      <el-table-column sortable align="center" label="图纸号" prop="shuoming" />
      <el-table-column sortable align="center" label="分配人" prop="createBy" />
      <el-table-column sortable align="center" label="工人" prop="userName" />
      <el-table-column sortable align="center" label="工人车间" prop="deptName" />
      <el-table-column sortable align="center" label="标准工时" prop="shuoming" show-overflow-tooltip />
      <el-table-column sortable align="center" label="分配数量" prop="count" />
      <el-table-column align="center" label="单价" prop="money" />
      <!--<el-table-column sortable align="center" label="完成数量" prop="finishCount" />-->
      <el-table-column sortable align="center"  label="完成数量" prop="finishCount">
        <template slot-scope="scope">
          <el-tooltip class="item" content="点击查看详情" effect="dark" placement="left-start">
            <span @click="baogongMingxiDetail(scope.row)" style="color: #00afff;cursor:pointer;">
              {{scope.row.finishCount}}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column sortable align="center" label="分配时间" prop="hour" />
      <el-table-column sortable align="center" label="总价" prop="allMoney" />
      <el-table-column sortable align="center" label="剩余完成数量" prop="remainCount" />
      <el-table-column sortable align="center" label="创建时间" prop="createTime" />
      <!-- <el-table-column align="center" label="备注" prop="remark"/>-->
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作" width="300px">
        <template slot-scope="scope">
          <el-button @click="baogongMingxiDetail(scope.row)" v-hasPermi="['develop:WeiwanchengTask:workDetailBnt']"
                     icon="el-icon-view" size="mini" type="text">
            报工明细
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <baogongMingxigDetail-list @ok="getList" ref="baogongMingxigDetail"></baogongMingxigDetail-list>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

  </el-dialog>
</template>

<script>
  import {
    deleteAction,
    getAction
  } from '@/api/manage'
  import BaogongMingxigDetailList from "@/views/develop/projectBaseInfo/prjForGoodsIn/BaogongMingxigDetailList";

  export default {
    name: "ShengchanDoGongxuUserForm",
    dicts: ['isdo', 'task_status', 'yes_no'],
    components: {
      BaogongMingxigDetailList,
    },
    data() {
      return {
        title: '',
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 销售产品物料选用明细表格数据
        dataList: [],
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          params: {},
          id: null,
          prodNo: null,
          shuoming: null,
          projectNo: null,
          gongyiCode: null,
          gongyiName: null,
          goodsName: null,
          goodsCode: null,
          projectCode: null,
          name: null,
          code: null,
          userName: null,
          deptId: null,
          status: null,
          ongxuName:null,
          gongxuModel:null,
          deptName:null,
          orderByColumn: "create_time",
          isAsc: "desc",
        },
        url: {
          list: '/goodsSaledoGongxuUser/goodsSaledoGongxuUser/list',
        },
        tableMaxHeight: window.innerHeight - 320,
      };
    },
    created() {
      window.addEventListener('resize', this.getTableHeight);
    },
    destroyed() {
      window.removeEventListener('resize', this.getTableHeight)
    },
    methods: {
      baogongMingxiDetail(row){
        this.$refs.baogongMingxigDetail.baogongMingxigShowDetail(row);
      },
      show(row) {
        this.open = true;
        this.title = "产品查看";
        this.queryParams.parentId = row.id;
        //this.queryParams.saleId = row.saleId;
        this.getList();
      },
      /** 查询销售产品物料选用明细列表 */
      getList() {
        this.loading = true;
        getAction(this.url.list, this.queryParams).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      getTableHeight() {
        this.tableHeight = window.innerHeight - 320
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
    }
  };
</script>
